package com.twu.biblioteca;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: Hugo
 * Date: 01/02/13
 * Time: 14:06
 * To change this template use File | Settings | File Templates.
 */
public class Data {
    private static Data instance = null;
    private List<String> menu = null;

    protected Data()
    {
        menu = new ArrayList<String>();
        menu.add("Menu");
        menu.add("1. View all books");
        menu.add("2. Reserve a book");
        menu.add("3. Membership Details");
        menu.add("4. Exit");
        menu.add("5. View all Movies");
        menu.add("6. Movie Details");
        menu.add("7. Log in");
    }

    public static Data GetInstance()
    {
        if(instance == null)
            instance = new Data();
        return instance;
    }

    public List<String> GetMenu()
    {
        return this.menu;
    }


    public boolean ReserveBook(String Name)
    {
        List<Book> books = GetAllBooks();
        if(books.contains(new Book(Name)))
        {
            return true;
        }
        return false;
    }

    public List<Book> GetAllBooks()
    {
        List<Book> books = new ArrayList<Book>();
        books.add(new Book("The Agile Samurai"));
        books.add(new Book("Agile Web Development with Rails"));
        books.add(new Book("Web Usability"));

        return books;
    }

    public Movie[] GetAllMovies()
    {
        Map<String, Movie> movieMap = GetAllMoviesAsMap();
        Movie[] allMovies = movieMap.values().toArray(new Movie[movieMap.size()]);
        return allMovies;
    }

    public Map<String, Movie> GetAllMoviesAsMap()
    {
        Map<String, Movie> allMovies = new HashMap<String, Movie>();
        allMovies.put("The Shawshank Redemption",new Movie("The Shawshank Redemption",1994,"Frank Darabont",9));
        allMovies.put("Pulp Fiction",new Movie("Pulp Fiction",1994,"Quentin Tarantino"));
        allMovies.put("The Godfather",new Movie("The Godfather",1972,"Francis Ford Coppola",7));
        allMovies.put("12 Angry Men",new Movie("12 Angry Men",1957,"Sidney Lumet",5));
        allMovies.put("The Dark Knight",new Movie("The Dark Knight",2008,"Christopher Nolan",9));
        allMovies.put("Schindler's List",new Movie("Schindler's List",2003,"Steven Spielberg"));
        allMovies.put("Fight Club",new Movie("Fight Club",1999,"David Fincher"));
        allMovies.put("Inception",new Movie("Inception",2010,"Christopher Nolan",3));
        allMovies.put("The Matrix",new Movie("The Matrix",1999,"Andy Wachowski",9));
        allMovies.put("Momento",new Movie("Momento",2000,"Christopher Nolan",9));
        allMovies.put("Disaster Movie",new Movie("Disaster Movie",2008,"Jason Friedberg",2));
        allMovies.put("Crossover", new Movie("Crossover",1994,"Preston A. Whitmore II",1));
        allMovies.put("Citizen Kane", new Movie("Citizen Kane",1941,"Preston A. Whitmore II",7));
        allMovies.put("Amelie", new Movie("Amelie",2001,"Jean-Pierre Jeunet",8));
        allMovies.put("Up", new Movie("Up",2009,"Pete Docter"));
        return allMovies;
    }

    public Movie GetMovie(String Title)
    {
        Map<String, Movie> allMovies = GetAllMoviesAsMap();
        if(allMovies.containsKey(Title))
        {
            return allMovies.get(Title);
        }
        else
        {
            return null;
        }
    }

    private List<User> GetAllUsers()
    {
        List<User> allUsers = new ArrayList<User>();
        allUsers.add(new User("111-1111","password","Hugo","hugo.firth@gmail.com","0427 097 244"));
        allUsers.add(new User("111-1112","password","User 2","user.3@gmail.com","0427 097 245"));
        allUsers.add(new User("111-1111","password","User 3","user.3@gmail.com","0427 097 246"));
        return allUsers;
    }

    public User UserLogon(String Username, String Password)
    {
        List<User> allUsers = GetAllUsers();
        for(int i = 0; i < allUsers.size(); i++) //I wish I had LINQ right now  :'(
        {
            if(allUsers.get(i).IsEqual(Username,Password))
            {
                return allUsers.get(i);
            }
        }
        return null;
    }
}
